      INTEGER FUNCTION KASKIT(TEXT,LUPROMPT,LUANSWER,MAXTRIES)
C
C THIS ROUTINE IS USED TO PROMPT THE USER FOR A YES/NO ANSWER TO A
C QUESTION OR STATEMENT SUPPLIED IN THE CALLING SEQUENCE.
C
C VARIABLE DIM TYPE I/O DESCRIPTION
C -------- --- ---- --- -----------
C
C TEXT      1 CH*(*) I  THE TEXT TO BE WRITTEN TO THE PROMPT UNIT.
C                       ONE LINE IS WRITTEN REGARDLESS OF THE
C                       LENGTH OF THE STRING. THERE IS NO CHECK TO
C                       SEE THAT IT FITS ON THE PROMPT UNIT.
C
C LUPROMPT  1   I*4  I  THE FORTRAN UNIT NUMBER TO WHICH THE TEXT
C                       IS WRITTEN. IF ZERO OR NEGATIVE, NO TEXT IS
C                       WRITTEN, BUT AN ANSWER IS EXPECTED AS THOUGH A
C                       PROMPT HAD OCCURRED.
C
C LUANSWER  1   I*4  I  THE FORTRAN UNIT NUMBER FROM WHICH THE PROGRAM
C                       READS THE RESPONSE. THE RESPONSE IS A SINGLE
C                       CHARACTER(NO LEADING BLANKS) AND MUST BE AN
C                       UPPER OR LOWER CASE 'Y' OR 'N'. IF NOT ONE OF
C                       THESE, THE PROGRAM KEEPS PROMPTING UNTIL A VALID
C                       ANSWER IS RECEIVED OR UNTIL THE MAXTRIES
C                       VARIABLE TAKES EFFECT.
C
C MAXTRIES  1   I*4  I  A VARIABLE INDICATING THE NUMBER OF INVALID
C                       REPLIES THE ROUTINE WILL ACCEPT DURING THIS 
C                       CALL. WHEN THIS MANY HAVE OCCURRED, THE ROUTINE
C                       EXITS WITH KASKIT = 3.
C
C                       ASSIGNMENTS:
C
C                       = NEGATIVE, AN UNLIMITED NUMBER IS PERMITTED
C                       = OTHERWISE, THE MAX NUMBER PERMITTED. 
C                         SPECIFICALLY, IF 0 OR 1, THE REPLY MUST BE 
C                         CORRECT THE FIRST TIME.
C
C KASKIT    1   I*4  O  THE ANSWER. ASSIGNMENTS ARE
C
C                       = 0, THE ANSWER IS NO.
C                       = 1, THE ANSWER IS YES.
C                       = 2, ANSWER IS UNKNOWN. AN END OF FILE WAS 
C                            FOUND ON UNIT LUANSWER.
C                       = 3, ANSWER IS UNKNOWN. TOO MANY INVALID REPLIES
C                            WERE ENTERED.
C
C   ***********
C   * EXAMPLE *
C   ***********
C
C     CODE IS :      KTEMP = KASKIT('OK TO PROCEED ?',6,5,3)
C
C     THE ROUTINE WRITES: OK TO PROCEED ?  ENTER (Y/N) >
C
C     THE TEXT APPEARS ON UNIT 6, THE ANSWER COMES FROM UNIT 5, AND
C       THE THIRD INVALID REPLY, IF IT OCCURS, TRIGGERS AN ERROR EXIT 
C       FROM THIS ROUTINE.
C
C***********************************************************************
C
C BY C PETRUZZO, GSCF/742. 11/84. 
C        MODIFIED....
C
C***********************************************************************
C
      LOGICAL VALID,OKNUM
      CHARACTER*1 CH1
      CHARACTER*(*) TEXT
C
C INITIALIZATION
C
      NASKED = 0      ! NUMBER OF PROMPTS MADE
      OKNUM = .TRUE.  ! FLAG INDICATING NUM OF INVALID RESPONSES IS OK
      VALID = .FALSE. ! FLAG INDICATING VALID RESPONSE RECEIVED
C
C
C KEEP PROMPTING UNTIL A VALID RESPONSE IS RECEIVED OR UNTIL AN
C EXCESSIVE NUMBER OF INVALID REPLIES HAVE BEEN MADE.

      DO WHILE ( OKNUM .AND. .NOT.VALID )
C      PROMPT.
        IF(LUPROMPT.GT.0) WRITE(LUPROMPT,1) TEXT
    1   FORMAT(//,1X,A,'  ENTER (Y/N) > ',$)
        NASKED = NASKED + 1
C      READ THE REPLY.
        JASKIT = 2   ! SET THIS IN CASE AND END-FILE OCCURS.
        READ(LUANSWER,2,END=9999) CH1
    2   FORMAT(A)
C      CHECK FOR 'Y'(=YES) REPLY
        IF( CH1.EQ.'Y' .OR. CH1.EQ.'y') THEN
          VALID = .TRUE.
          JASKIT = 1
          END IF
C      CHECK FOR 'N'(=NO) REPLY
        IF( CH1.EQ.'N' .OR. CH1.EQ.'n') THEN
          VALID = .TRUE.
          JASKIT = 0
          END IF
C      ERROR CHECK
        IF(.NOT.VALID) THEN
          IF(LUPROMPT.GT.0) WRITE(LUPROMPT,3)
    3     FORMAT(//,
     *      ' >>>> INVALID ANSWER. FIRST CHARACTER IS NOT Y AND ',
     *            'IS NOT N.')
          IF(MAXTRIES.GE.0) THEN
            IF(NASKED.GE.MAXTRIES) THEN
C            EXCESSIVE INVALID REPLIES.
              JASKIT = 3
              OKNUM = .FALSE.  ! FORCES THE EXIT.
              END IF
            END IF
          END IF
        END DO
C
C
C SET THE OUTPUT VALUE.
C
 9999 CONTINUE
      KASKIT = JASKIT
C
      RETURN
      END
